#include "ClassificationMenu.h"
#include "StringUtilities.h"
#include "PrintUtilities.h"
#include "User.h"
#include "League.h"
#include "LeagueManager.h"
#include "MenuManager.h"
#include "TeamManager.h"
#include "GamePrintUtils.h"
#include "TeamMenu.h"
#include "Types.h"

ClassificationMenu::ClassificationMenu(MenuManager* const i_menuManager)
	: Menu(i_menuManager)
	, m_leagueID(Utilities::INVALID_ID)
{
}

void ClassificationMenu::Draw() const
{
	STD::cout << Print::Title("CLASSIFICATION:");
	const LeagueVec& leagues = GetSP()->GetLeagueMgr().GetLeagues(true);

	const League& league = *leagues.at(m_leagueID);
	STD::cout << "LEAGUE " << league.GetName() << STD::endl;
	PrintClassification(STD::cout, league, GetSP());
	STD::cout << STD::endl;

	STD::cout << Print::Options("xyz) Select team.\n\n0) Return to previous menu'") << " Selection: ";
}

bool ClassificationMenu::Input(const STL::string& i_input)
{
	bool goodInput = true;

	size_t res = Utilities::StringToInt(i_input);

	if (res == 0)
	{
		GetMM()->SetMenu(GetMM()->GetLeagueStatsMenu());
	}
	else if (res > 0 && res <= GetSP()->GetLeagueMgr().GetNumOfTeams(false))
	{
		TeamMenu* nextMenu = static_cast<TeamMenu*>(GetMM()->GetTeamMenu());
		nextMenu->SetTeamID(res-1);
		GetMM()->PushMenu(nextMenu);
	}
	else
	{
		goodInput = false;
	}

	return goodInput;
}